home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Tele / Pete Johnson / TSet 1.6<source> Folder / TSet.p < prev    next >
Encoding:
Text File  |  1992-04-12  |  5.4 KB  |  171 lines  |  [TEXT/PJMM]

  1. program TSet;
  2.  
  3. {    Tabby NetMail utility to read 'Next Event' file and update Config file.                    }
  4. {    Written by Pete Johnson                                                                        }
  5.  
  6. {    Version 1.6                                                                                        }
  7. {    Last altered May 26,1991                                                                    }
  8.  
  9. {    Revision history:                                                                                }
  10. {    06/15/89:    Added separate unit to read Config file and went to Toolbox file calls    }
  11. {    07/22/89:    Cleaned up code.                                                                    }
  12. {    11/6/89:    Reduced memory demands.                                                    }
  13. {    11/18/89    WaitNextEvent added for MF compatibility                                    }
  14. {    05/26/91    V 1.6 added SIZE resource & WaitNextEvent calls                                }
  15.  
  16.     uses
  17.         Globals, HelloTabby, HostFile;
  18.  
  19.     type
  20.         NextTime = packed array[1..4] of char;
  21.         NextTimePtr = ^NextTime;
  22.         NextTimeHdl = ^NextTimePtr;
  23.         HostTime = packed array[1..3] of char;
  24.         HostTimePtr = ^HostTime;
  25.         HostTimeHdl = ^HostTimePtr;
  26.  
  27.     var
  28.         LaunchHour, LaunchMinute, EventRefNum, ConfigRef: integer;
  29.         NextLaunchTime, NowSeconds, logicalEOF, CharsToSend: longint;
  30.         NowDateRec: DateTimeRec;
  31.         TheNextTimeHdl: NextTimeHdl;
  32.         TheHostTimeHdl: HostTimeHdl;
  33.  
  34. { ------------------------------------------------------ }
  35.  
  36.     function Make2Digits (ConvertFrom: string): integer;
  37.  
  38. {    Converts two-character string into an ASCII value        }
  39.  
  40.         var
  41.             Num1, Num2: integer;
  42.  
  43.     begin
  44.         Num1 := ord(ConvertFrom[1]) - ord('0');
  45.         Num2 := ord(ConvertFrom[2]) - ord('0');
  46.         Make2Digits := Num2 + (Num1 * 10)
  47.     end;
  48.  
  49. { ------------------------------------------------------ }
  50.  
  51.     procedure HandleDialog;
  52.  
  53.         var
  54.             theDialog: DialogPtr;
  55.             ItemHit, itemType, whichItem: integer;
  56.             itemHandle: Handle;
  57.             dispRect: Rect;
  58.             thisButton: ControlHandle;
  59.  
  60.     begin
  61.         InitCursor;
  62.         theDialog := GetNewDialog(1002, nil, POINTER(-1));                {IM I-413}
  63.         SetPort(theDialog);
  64.         FrameDItem(theDialog, Ok);
  65.         DrawDialog(theDialog);
  66.  
  67.         NextLaunch := GetString(500)^^;        {    Get next launch string from resource    }
  68.         getDItem(theDialog, 3, itemType, itemHandle, dispRect);
  69.         SetIText(Handle(itemHandle), NextLaunch);
  70.  
  71.         if StillDown then
  72.             repeat
  73.             until not Button;
  74.  
  75.         repeat
  76.             ModalDialog(nil, ItemHit);                                            {IM I-415}
  77.             ;
  78.             case ItemHit of
  79.  
  80.                 1: { OK button hit -- save resources }
  81.                     begin
  82.                         getDItem(theDialog, 3, itemType, itemHandle, dispRect);
  83.                         GetIText(Handle(itemHandle), NextLaunch);
  84.                         RmveResource(Handle(GetResource('STR ', 500)));
  85.                         UpdateResFile(CurrentResFile);
  86.                         AddResource(Handle(NewString(NextLaunch)), 'STR ', 500, 'Next Launch');
  87.                     end;
  88.  
  89.                 2: 
  90.                     ; { Cancel button hit—do nothing    }
  91.  
  92.                 otherwise
  93.                     ;    {    do nothing    }
  94.  
  95.             end;
  96.         until (ItemHit = 1) or (ItemHit = 2);
  97.  
  98.         DisposDialog(theDialog)
  99.     end;
  100.  
  101. { ------------------------------------------------------ }
  102.  
  103. begin
  104.     CurrentResFile := CurResFile;
  105.     if Button then
  106.         HandleDialog        { If user is holding down the mouse button, reconfigure and end        }
  107.     else
  108.         begin
  109.             HelloTabby;                                                {    Find out what's next on the launchpad    }
  110.             if MultiFinder then
  111.                 IgnoreBool := WaitNextEvent(EveryEvent, TabbyEventRec, sleep, nil);
  112.             TheNextTimeHdl := NextTimeHdl(NewHandle(sizeOf(NextTime)));
  113.             TheHostTimeHdl := HostTimeHdl(NewHandle(sizeOf(HostTime)));
  114.             ReadConfig;
  115.             if MultiFinder then
  116.                 IgnoreBool := WaitNextEvent(EveryEvent, TabbyEventRec, sleep, nil);
  117.             Err := GetVol(nil, vRefNum);        { Get volume ref # for default volume }
  118.             Err := FSOpen(':Next Event', vRefNum, EventRefNum);
  119.             Err := GetEOF(EventRefNum, logicalEOF);
  120.             if (logicalEOF > 0) & (Err = NoErr) then
  121.                 begin
  122.                     if MultiFinder then
  123.                         IgnoreBool := WaitNextEvent(EveryEvent, TabbyEventRec, sleep, nil);
  124.                     CharsToSend := 4;
  125.                     Err := FSRead(EventRefNum, CharsToSend, Ptr(TheNextTimeHdl^));
  126.                     Err := FSClose(EventRefNum);
  127.  
  128.                     LaunchHour := Make2Digits(copy(TheNextTimeHdl^^, 1, 2));
  129.                     LaunchMinute := Make2Digits(copy(TheNextTimeHdl^^, 3, 2));
  130.  
  131.                     GetDateTime(NowSeconds);
  132.                     Secs2Date(NowSeconds, NowDateRec);
  133.  
  134.                     with NextLaunchDateRec do
  135.                         begin
  136.                             year := NowDateRec.year;                {    Set up the current year for the Config file            }
  137.                             month := NowDateRec.month;            {    Set up the current month for the Config file        }
  138.                             day := NowDateRec.day;                {    Set up the current day for the Config file            }
  139.                             hour := LaunchHour;                        {    Set up the next launch hour for the Config file        }
  140.                             minute := LaunchMinute;                {    Set up the next launch minute for the Config file    }
  141.                             second := 0;                                {    Don't care about seconds                                }
  142.                             if (hour < NowDateRec.hour) then    {    Hour has passed -- set day to tomorrow            }
  143.                                 day := day + 1
  144.                             else if (hour = NowDateRec.hour) and (minute <= NowDateRec.minute) then
  145.                                 day := day + 1;                            {    Same hour, but minute has passed -- set day to tomorrow    }
  146.                             TheHostTimeHdl^^[1] := char(LaunchHour);
  147.                             TheHostTimeHdl^^[2] := char(LaunchMinute);
  148.                             TheHostTimeHdl^^[3] := char(0);        {    Seconds are always zero    }
  149.                         end;            {    with NextLaunchDateRec do    }
  150.  
  151.                     Date2Secs(NextLaunchDateRec, NextLaunchTime);
  152.                     Err := FSOpen('Config', vRefNum, ConfigRef);
  153.                     Err := SetFPos(ConfigRef, fsFromStart, 224);
  154.                     CharsToSend := 3;
  155.                     Err := FSWrite(ConfigRef, CharsToSend, Ptr(TheHostTimeHdl^));
  156.                     Err := SetFPos(ConfigRef, fsFromStart, 308);
  157.                     CharsToSend := 4;
  158.                     Err := FSWrite(ConfigRef, CharsToSend, Ptr(@NextLaunchTime));
  159.                     Err := FSClose(ConfigRef);
  160.                 end;
  161.             Err := FSClose(EventRefNum);
  162.  
  163.             DisposHandle(Handle(TheNextTimeHdl));
  164.             DisposHandle(Handle(TheHostTimeHdl));
  165.             if MultiFinder then
  166.                 IgnoreBool := WaitNextEvent(EveryEvent, TabbyEventRec, sleep, nil);
  167.  
  168.             if NextLaunch <> '' then
  169.                 LaunchNextAppl
  170.         end;
  171. end.